import {Component, OnInit} from '@angular/core';
import {ApisService} from '../shared/services/requests/apis.service';
import {RequestsService} from '../shared/services/requests/requests.service';
import {dcBasicInfo} from '../shared/interface/datas/dcBasicInfo';
import {PieChartComponent} from "../shared/components/pie-chart/pie-chart.component";

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {

  pieChart: any;

  loading: boolean;

  private dcBasicInfo = {};
  private dcBasicInfoApi = this.apis.apis.dcBasicInfo;

  constructor(private apis: ApisService,
              private req: RequestsService) {
  }

  /**
   * *************************************************************************
   * 请求后台数据,获取dc基本信息
   *
   */
  private getDcBasicInfo(): void {

    this.loading = true;

    this.req.getData(this.dcBasicInfoApi)
      .subscribe(res => {
        res as dcBasicInfo;
        let val:dcBasicInfo = res;
        console.log("获取到的dcBasicInfo数据");
        console.log(val);
        this.dcBasicInfo = val;
        console.log(this.dcBasicInfo);
        // this.dcBasicInfo.avgTemp = val.avgTemp;
        // this.dcBasicInfo.power = val.power;
        // this.dcBasicInfo.rHumidity = val.rHumidity;
        this.loading = false;
      }, err => {
        this.loading = false;
      })
  }

  ngOnInit() {
    this.getDcBasicInfo();
  }

}
